From e2e1751a06b1ba79b651417343bb27ee04140d34 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 3 Aug 2015 15:10:31 -0700 Subject: [PATCH] Fix activating features in dependencies transitively When activating the feature `foo/bar` you're actually activating both the feature `foo` and the `bar` feature of the relevant package. Cargo previously forgot to activate the `foo` feature, and this commit fixes that up. Closes #1871 --- src/cargo/core/resolver/mod.rs | 1 + tests/test_cargo_features.rs | 38 ++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/src/cargo/core/resolver/mod.rs b/src/cargo/core/resolver/mod.rs index 0fe74b8d8..223966a9d 100644 --- a/src/cargo/core/resolver/mod.rs +++ b/src/cargo/core/resolver/mod.rs @@ -556,6 +556,7 @@ fn build_features(s: &Summary, method: Method) match parts.next() { Some(feat) => { let package = feat_or_package; + used.insert(package.to_string()); deps.entry(package.to_string()) .or_insert(Vec::new()) .push(feat.to_string()); diff --git a/tests/test_cargo_features.rs b/tests/test_cargo_features.rs index 33a058f0e..11211087b 100644 --- a/tests/test_cargo_features.rs +++ b/tests/test_cargo_features.rs @@ -769,3 +769,41 @@ test!(optional_and_dev_dep { {compiling} test v0.1.0 ([..]) ", compiling = COMPILING))); }); + +test!(activating_feature_activates_dep { + let p = project("foo") + .file("Cargo.toml", r#" + [package] + name = "test" + version = "0.1.0" + authors = [] + + [dependencies] + foo = { path = "foo", optional = true } + + [features] + a = ["foo/a"] + "#) + .file("src/lib.rs", " + extern crate foo; + pub fn bar() { + foo::bar(); + } + ") + .file("foo/Cargo.toml", r#" + [package] + name = "foo" + version = "0.1.0" + authors = [] + + [features] + a = [] + "#) + .file("foo/src/lib.rs", r#" + #[cfg(feature = "a")] + pub fn bar() {} + "#); + + assert_that(p.cargo_process("build").arg("--features").arg("a").arg("-v"), + execs().with_status(0)); +}); -- 2.30.2